﻿/*----------------------------------------------------------------
//Copyright (C) 2012 赵国伟
//文件功能描述：词典管理客户端脚本
//创建人：赵国伟
//生成时间：2012-04-05 00:42:54
//----------------------------------------------------------------*/
var AjaxServerUrl = "/Manage/AS/DictionaryCommon.aspx";
var ModelOfDictionary;
var DictionaryID = 0;
var SelectOptionOfDictionary = "";

///初始化
function Init() {
    DictionaryID = 0;
}
///执行搜索；
function GoToSearch() {
    var url = "DictionariesManage.aspx?";
    url += "Category=" + escape($("#ddlCategoryOfSearch").val().trim());
    url += "&Status=" + escape($("#ddlStatusOfSearch").val().trim());
    location.href = url;
}

//执行删除
function Delete(id) {
    if (!confirm("系统提示：您确定要删除该条词典信息？"))
        return;
    AjaxGet(AjaxServerUrl + "?Action=DeleteDictionary&DictionaryID=" + id);
}

///检查表单；
function CheckForm() {
    if ($("#ddlCategory").val() == "") {
        alert("系统提示：请选择词分类！");
        $("#ddlCategory").focus();
        return false;
    }
    if ($("#txtDictionaryName").val() == "") {
        alert("系统提示：请输入词名称！");
        $("#txtDictionaryName").focus();
        return false;
    }
    if (!IsNumber($("#txtOrderValue").val())) {
        alert("系统提示：排序值必须为数字！");
        $("#txtOrderValue").focus();
        return false;
    }
    return true;
}

//保存；
function Save() {
    $("#btnSave").attr("disabled", true);
    if (!CheckForm()) {
        $("#btnSave").attr("disabled", false);
        return;
    }

    var data = clone(ModelOfDictionary);
    data._dictionaryid = DictionaryID;
    data._category = $("#ddlCategory").val();
    data._dictionaryname = $("#txtDictionaryName").val();
    data._ordervalue = $("#txtOrderValue").val();
    data._status = $("#ddlStatus").val();
    data._memo = $("#txtMemo").val();
    data._createdate = "/Date(" + CurrentDateStringToUTC() + ")/";
    var url = AjaxServerUrl + "?Action=SaveDictionary";
    AjaxPost(url, "btnSave", data);  //更新
}

//绑定词典信息到录入表单中；
function BindDictionaryToForm() {
    var url = AjaxServerUrl + "?action=GetDictionaryInfo&DictionaryID=" + DictionaryID + "&tttt=" + Math.random();
    $.ajax(
    {
        type: "Get",
        url: url,
        dataType: "json",
        success: function (data) {
            if (data != null) {
                $("#ddlCategory").val(data._category);
                $("#txtDictionaryName").val(data._dictionaryname);
                $("#txtOrderValue").val(data._ordervalue);
                $("#txtMemo").val(data._memo);
                $("#ddlStatus").val(data._status);
            }
        }
    });
}

///添加界面；
function Add() {
    Init();
    GetPopupDiv(600, 800, "#e2e2e2", "添加词典", GetHtmlForm());
}

//编辑界面；
function Edit(id) {
    Init();
    DictionaryID = id;
    GetPopupDiv(600, 800, "#e2e2e2", "编辑词典", GetHtmlForm());
    BindDictionaryToForm();
}

///获取录入界面的HTML;
function GetHtmlForm() {
    var html = new Array();
    html.push("<form>");
    html.push("<table width=\"600\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"table\">");
    html.push("  <tr>");
    html.push("    <td colspan=\"2\" class=\"TableHeadRow\">&gt;&gt;词信息</td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">词类别：</td>");
    html.push("    <td><select name=\"ddlCategory\" id=\"ddlCategory\">");
    html.push("<option value=\"\">--请选择词类别--</option>");
    html.push(SelectOptionOfDictionary);
    html.push("    </select>");
    html.push("    </td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td width=\"97\" align=\"right\">词名称：</td>");
    html.push("    <td width=\"503\"><input name=\"txtDictionaryName\" type=\"text\"  class=\"border6\" id=\"txtDictionaryName\" size=\"30\">");
    html.push("    <span class=\"red\">(*)</span></td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">排序值：</td>");
    html.push("    <td><input name=\"txtOrderValue\" type=\"text\" class=\"border6\" id=\"txtOrderValue\" value=\"0\" size=\"5\" />");
    html.push("      <span class=\"red\">(*)</span></td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">备注：</td>");
    html.push("    <td><textarea name=\"txtMemo\" cols=\"50\" id=\"txtMemo\" rows=\"3\"></textarea>");
    html.push("      <span class=\"red\">(*)</span></td>");
    html.push("  </tr>");

    html.push("  <tr>");
    html.push("    <td align=\"right\">状态：</td>");
    html.push("    <td><select name=\"ddlStatus\" id=\"ddlStatus\">");
    html.push("	 <option value=\"正用\">正用</option>");
    html.push("	  <option value=\"停用\">停用</option>");
    html.push("    </select>    </td>");
    html.push("  </tr>");
    html.push("  <tr>");
    html.push("    <td align=\"right\">&nbsp;</td>");
    html.push("    <td><input name=\"btnSave\" type=\"button\" id=\"btnSave\" value=\" 保 存 \" class=\"btn2\" onclick=\"Save();\">");
    html.push("    <input name=\"btnReset\" type=\"reset\" id=\"btnReset\" value=\" 重 置 \" class=\"btn2\">");
    html.push("    <input name=\"btnClose\" type=\"button\" id=\"btnClose\" value=\"关闭本窗口\" class=\"btn2\" onclick=\"yesOther(false);\"></td>");
    html.push("  </tr>");
    html.push("</table>");
    html.push("</form>");

    return html.join("");

}













